<?php

/**
 * 首页达人推荐管理-新增
*
* @copyright zhanghuan
* @since 2012-03-23
*/

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/index/db_food_user_daren_index.class.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	//uid
	cgi::both($g_cgival["uid"], "uid", '');
	if (!cgi_chk::uid($g_cgival["uid"]) && !empty($g_cgival["uid"]))
	{
		throw new Exception("参数uid错误");
	}
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	$position_data = array(1,2,3,4,5,6,7,8,9);
	$uid = $g_cgival["uid"];
	$cur_item = array();
	
	// 实例化
	$db = new db_food_user_daren_index();
	
	if (!empty($uid))
	{
		$cur_item = $db->admin_get_item_by_uid($uid, $site_id);
	}
	// 获取达人记录数据
	$data = $db->admin_get_list_by_site_id($site_id);
	
	if (!empty($data))
	{
		foreach ($data as $item)
		{
			if (isset($cur_item["pos"]) && $cur_item["pos"] == $item["pos"])
			{
			}
			else 
			{
				$position_data = array_diff($position_data, array($item["pos"]));
			}
		}
	}
	$g_show["position_data"] = $position_data;
	$g_show["data"] = $cur_item;
}

try
{
	admin_check_login();

	check_cgi_pro();
	get_data();
	
	$g_show["error"] = 0;
	$g_show["errmsg"] = "";
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit;

function show_pro()
{
	global $g_show;
	$smarty = p_get_smarty ();
	$smarty->assign ($g_show );
	$smarty->display ( "foodv2/index/user_daren_add.html" );
}
?>